define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {

        //达人身份认证
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'qzuser/qzuserrz/index',
                    add_url: 'qzuser/qzuserrz/add',
                    edit_url: 'qzuser/qzuserrz/edit',
                    del_url: 'qzuser/qzuserrz/del',
                    multi_url: 'qzuser/qzuserrz/multi',
                    table: 'qzuser/qzuserrz',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'userid',
                sortName: '',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'userid', title: __('用户ID'), sortable: true},
                        {field: 'img', title: __('头像'), formatter: Table.api.formatter.image, operate: false},
                        {field: 'nickname', title: __('昵称'),operate: 'LIKE'},
                        {field: 'diqu', title: __('地区')},
                        {field: 'sex', title: __('性别'), visible: false, searchList: {0: __('未知'), 1: __('男'),2:__('女')}},
                        {field: 'age', title: __('年龄')},
                        {field: 'tige', title: __('身高/体重'),visible: false},
                        {field: 'phone', title: __('手机号')},
                        {field: 'use_type', title: __('用户身份'), visible: false, searchList: {1: __('普通'), 2: __('达人'),3:__('商家')}},
                        {field: 'prased', title: __('获赞量'),sortable: true},
                        {field: 'card_num', title: __('体验卡数量'),sortable: true},

                        {field: 'positive_id_card_img', title: __('身份证正面'), formatter: Table.api.formatter.image, operate: false},
                        {field: 'back_id_card_img', title: __('身份证反面图片'), formatter: Table.api.formatter.image, operate: false},
                        {field: 'hold_id_card_img', title: __('手持身份证照片'), formatter: Table.api.formatter.image, operate: false},


                        {field: 'creat_time', title: __('创建时间'),formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        { field: 'rz_state', title: __('审核状态'), operate: false, searchList: {0: __('未通过'), 1: __('审核中'),2:__('通过')}},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                        {
                            field: 'buttons',
                            width: "220px",
                            title: __('操作'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'edit',
                                    text: __(''),
                                    title: __('通过'),
                                    classname: 'btn btn-xs btn-success btn-magic btn-ajax',
                                    icon: 'fa fa-check',
                                    confirm: '确定通过该审核吗?',
                                    url: 'qzuser/qzuserrz/edit?editstate=2&edittype=sh',
                                    hidden:function(row){
                                        if(row.rz_state == '1'){
                                            return true;
                                        }
                                    }
                                },
                                {
                                    name: 'edit',
                                    text: __(''),
                                    title: __('驳回'),
                                    classname: 'btn btn-xs btn-warning btn-magic btn-ajax',
                                    icon: 'fa fa-close',
                                    confirm: '确定驳回该文章吗?',
                                    url: 'qzuser/qzuserrz/edit?editstate=0&edittype=sh',
                                    hidden:function(row){
                                        if(row.rz_state == '1'){
                                            return true;
                                        }
                                    }
                                },
                                {
                                    name: 'edit',
                                    text: __('编辑'),
                                    title: __('编辑'),
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: 'fa fa-list',
                                    url: 'qzuser/qzuserrz/edit',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        return true;
                                    }
                                },
                                {
                                    name: 'addtabs',
                                    text: __('查看'),
                                    title: __('查看详情'),
                                    classname: 'btn btn-xs btn-warning btn-addtabs',
                                    icon: 'fa fa-folder-o',
                                    url: 'qzuser/qzuserrz/detail'
                                }
                            ],
                            formatter: Table.api.formatter.buttons
                        },
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },


        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
        }
    };
    return Controller;
});